from rest_framework.views import exception_handler
from rest_framework.response import Response

def common_exception_handler(exc, context):
    response = exception_handler(exc, context)
    if response:
        if isinstance(response.data,list):
            err=response.data[0]
        elif isinstance(response.data, dict):
            err = response.data.get('detail', '系统错误，请联系系统管理员')
        else:
            err='系统错误，请联系系统管理员'
        return Response({'code':101,'msg': f'{err}'})
    else:

        return Response({'code': 102, 'msg': '其他错误'})
